<h2>Why is this an issue?</h2>
<p>In a Spring application, the <code>@DirtiesContext</code> annotation marks the ApplicationContext as dirty and indicates that it should be cleared
and recreated. This is important in tests that modify the context, such as altering the state of singleton beans or databases.</p>
<p>Misconfiguring <code>@DirtiesContext</code> by setting the <code>methodMode</code> at the class level or the <code>classMode</code> at the method
level will make the annotation have no effect.</p>
<p>This rule will raise an issue when the incorrect mode is configured on a @DirtiesContext annotation targeting a different scope.</p>
<h2>How to fix it</h2>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
@ContextConfiguration
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD) // Noncompliant, for class-level control, use classMode instead.
public class TestClass {
  @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) // Non compliant, for method-level control use methodMode instead
  public void test() {...}
}
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
@ContextConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class TestClass {
  @DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
  public void test() {...}
}
</pre>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
  <li> Spring documentation - <a
  href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/annotation/DirtiesContext.html">@DirtiesContext</a>
  </li>
</ul>

